﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;

public partial class ReporteEmpresas : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                if (Session["iduser"] == null || Session["iduser"].ToString() == "0")
                {
                    Response.Redirect("index.aspx");
                }
                else
                {
                    DataSet ds = new DataSet();
                    wcfBolsa.Service1 wb = new wcfBolsa.Service1();
                    ds = wb.ListarPefilEmpresas();

                    DataTable dt = new DataTable();
                    dt.TableName = "Empresas";

                    dt.Columns.Add("IdRegistroEmpresa", typeof(string));
                    dt.Columns.Add("Cargo", typeof(string));
                    dt.Columns.Add("Salario", typeof(string));
                    dt.Columns.Add("Lugar", typeof(string));
                    dt.Columns.Add("Requisitos", typeof(string));
                    dt.Columns.Add("Educacion", typeof(string));
                    dt.Columns.Add("Duracion", typeof(string));
                    dt.Columns.Add("Horario", typeof(string));


                    int j = 0;
                    for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
                    {
                        dt.Rows.Add(j);
                        dt.Rows[j].BeginEdit();
                        dt.Rows[j]["IdRegistroEmpresa"] = ds.Tables[0].Rows[j][0];
                        dt.Rows[j]["Cargo"] = ds.Tables[0].Rows[j][4];
                        dt.Rows[j]["Salario"] = ds.Tables[0].Rows[j][12];
                        dt.Rows[j]["Lugar"] = ds.Tables[0].Rows[j][7];
                        dt.Rows[j]["Requisitos"] = ds.Tables[0].Rows[j][1];
                        dt.Rows[j]["Educacion"] = ds.Tables[0].Rows[j][2];
                        dt.Rows[j]["Duracion"] = ds.Tables[0].Rows[j][10];
                        dt.Rows[j]["Horario"] = ds.Tables[0].Rows[j][11];

                        dt.Rows[j].EndEdit();
                        j++;
                    }

                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }
        catch (Exception ex)
        {


            EventLog LogErr = new EventLog();
            if (!EventLog.SourceExists("WebContrataci"))
            {
                EventLog.CreateEventSource("WebContrataci", "Application");
                LogErr.Source = "WebContrataci";
                LogErr.WriteEntry(ex.ToString(), EventLogEntryType.Information, 1);
            }
            else
            {

                LogErr.Source = "WebContrataci";
                LogErr.WriteEntry(ex.ToString());
            }
        }
        
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int dato;

        try
        {
            if (e.CommandName == "VerEmpresa")
            {
                dato = int.Parse(e.CommandArgument.ToString());

                DataSet ds = new DataSet();
                wcfBolsa.Service1 wb = new wcfBolsa.Service1();
                ds = wb.UnaEmpresaRegistro(dato, true);

                DataTable dt = new DataTable();
                dt.TableName = "Registro";
                dt.Columns.Add("Nombre", typeof(string));
                dt.Columns.Add("NombreComercial", typeof(string));
                dt.Columns.Add("Direccion", typeof(string));
                dt.Columns.Add("Telefono", typeof(string));
                dt.Columns.Add("WWW", typeof(string));
                dt.Columns.Add("Email", typeof(string));
                dt.Columns.Add("Informacion", typeof(string));


                int j = 0;
                for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
                {
                    dt.Rows.Add(j);
                    dt.Rows[j].BeginEdit();
                    dt.Rows[j]["Nombre"] = ds.Tables[0].Rows[j][3];
                    dt.Rows[j]["NombreComercial"] = ds.Tables[0].Rows[j][4];
                    dt.Rows[j]["Direccion"] = ds.Tables[0].Rows[j][6];
                    dt.Rows[j]["Telefono"] = ds.Tables[0].Rows[j][7];
                    dt.Rows[j]["WWW"] = ds.Tables[0].Rows[j][8];
                    dt.Rows[j]["Email"] = ds.Tables[0].Rows[j][9];
                    dt.Rows[j]["Informacion"] = ds.Tables[0].Rows[j][10];
                    dt.Rows[j].EndEdit();
                    j++;
                }

                GridView2.DataSource = dt; //ds.Tables[0];
                GridView2.DataBind();


            }
        }
        catch (Exception ex)
        {


            EventLog LogErr = new EventLog();
            if (!EventLog.SourceExists("WebContrataci"))
            {
                EventLog.CreateEventSource("WebContrataci", "Application");
                LogErr.Source = "WebContrataci";
                LogErr.WriteEntry(ex.ToString(), EventLogEntryType.Information, 1);
            }
            else
            {

                LogErr.Source = "WebContrataci";
                LogErr.WriteEntry(ex.ToString());
            }
        }
    }

}